/*
 * ClockView.hpp
 *
 *  Created on: Apr 29, 2009
 *      Author: asantos
 */


class ClockView{
public:
	typedef void(TickHandler)(long,long);
private:
	SignalBroker& signalbroker;
	Signal<TickHandler>& tick;
public:
	ClockView(SignalBroker& signalbroker, unsigned int milliseconds = 30):
		signalbroker(signalbroker),
		tick(signalbroker.CreateOrGetExistingSignal<TickHandler>("/clock/tick")){

	}
	void Start(){
		signalbroker.InvokeSignal<OutputStreamView::LogHandler>("/log/output", "Starting clock.");
		long t = SDL_GetTicks();
		long dt = 0;
		while(true){
			dt=SDL_GetTicks()-t;
			t+=dt;
			tick(t, dt);
		}
	}
};
